$(function () {
    var settings = {
        url: ctx + "role/list",
        pageSize: 10,
        queryParams: function (params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
                roleName: $(".role-table-form").find("input[name='roleName']").val().trim()
            };
        },
        columns: [{
            checkbox: true
        }, {
            field: 'roleName',
            title: '角色'
        }, {
            field: 'remark',
            title: '描述'
        }, {
            field: 'createTime',
            title: '创建时间'
        }]
    };

    $MB.initTable('roleTable', settings);
});

function search() {
    $MB.refreshTable('roleTable');
}

function refresh() {
    $(".role-table-form")[0].reset();
    search();
}

function deleteRoles() {
    var selected = $("#roleTable").bootstrapTable('getSelections');
    var selected_length = selected.length;
    if (!selected_length) {
        $MB.n_warning('请勾选需要删除的角色！');
        return;
    }
    var ids = "";
    for (var i = 0; i < selected_length; i++) {
        ids += selected[i].roleId;
        if (i !== (selected_length - 1)) ids += ",";
    }

    $MB.confirm({
        text: "删除选中角色将导致该角色对应账户失去相应的权限，确定删除？",
        confirmButtonText: "确定删除"
    }, function () {
        $.post(ctx + 'role/delete', {"ids": ids}, function (r) {
            if (r.code === 0) {
                $MB.n_success(r.msg);
                refresh();
            } else {
                $MB.n_danger(r.msg);
            }
        });
    });
}

function exportRoleExcel() {
    $.post(ctx + "role/excel", $(".role-table-form").serialize(), function (r) {
        if (r.code === 0) {
            window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $MB.n_warning(r.msg);
        }
    });
}

function exportRoleCsv() {
    $.post(ctx + "role/csv", $(".role-table-form").serialize(), function (r) {
        if (r.code === 0) {
            window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $MB.n_warning(r.msg);
        }
    });
}




var arr = new Array()
var number = 0 ;
document.onkeydown = function(e){
    var ev = document.all ? window.event : e;
    if(ev.keyCode==13) {
        number = 1;
        var inpText = $("#inputTxt").val();
        var array = new Array();
        var strA = inpText.slice(7,14);
        var strB = inpText.slice(15,18);
        var strC = inpText.slice(19,32);
        array = ["",strA,strB,strC];
        arr.push(array);
        console.log(arr)
        var bottom = document.getElementById('bottom');
        but();
    }
}
function but(){
    function setDiv(item,j,i) {
        if (j == 1) {
            var div = '';
        } else{
            var div = '<tr><td>'+ i +'</td><td>' + item[0] + '</td><td>' + item[1] + '</td><td>' + item[2] + '</td><td>' + item[3] + '</td><td><input type="button" value="删除" class="btn-xiugai" onclick="butt(' + i + ')"></td></tr>'
            //var div = '<div><label id="la1">' + item[0] + '</label><label id="la2">' + item[1] + '</label><label id="la3">' + item[2] + '</label><label id="la4">' + item[3] + '</label><button onclick="butt(' + i + ')">删除</button></div>';
        }
        return div
    }
    function getnoApplicationData() {
        var html = ''
        if (arr.length == 0) {
            var j = 1;
            html += setDiv(item,j,i)
            bottom.innerHTML = html
        } else{
            for (var i = 0; i < arr.length + 1; i++) {
                var j = 0;
                var item = arr[i]
                html += setDiv(item,j,i+1)
                var numberstr = i + 1;
                $("#mjob2_fy_xs").html('共'+numberstr+'条数据')
                bottom.innerHTML = html
            }
        }
    }
    $("#inputTxt").val('');
    document.getElementById('inputTxt').focus()//使光标一直在input内
    if (number == 1) {
        var ele = document.getElementById('table-cont');
        ele.scrollTop = ele.scrollHeight;
    }
    window.onload = getnoApplicationData()
    //<span style="color:#FF0000;">id="location"</span>
}
function butt(i){
    number = -1;
    arr.splice(i-1,1)
    console.log(arr)
    but();

}

function nextStep(){
    localStorage.setItem('panelForm', JSON.stringify(arr));
    window.location.href = "panelConfirm.html";
}
function blankClick(){
    document.getElementById('inputTxt').focus()//使光标一直在input内
}
//[)>061P471880A.101SMA18110051776Q110D181152PMXPD-243SI011V9W18VLENSN4LCN
